/**
 * 现场审核
 * Created by caijy on 2019/9/12.
 */
define(function () {

    var self,
        app = win.app,
        searchData = {
            keyword: ''
        },
        selectArg
    ;

    app.newModule({

        init: function () {
            self = this;
            self.data={

            }
            self._super({
                // 最先执行
                _readyBefore: function () {
                    selectArg = self._pageParameters;
                    searchData.keyword = selectArg.keyword;
                },
                // 搜索
                _search: {
                    data:searchData,
                    methods: {
                        toScan: self.toScan
                    }
                },
                _refreshAutoInit: true //自动加载刷新控件
            }, win);
        },
        _initRefresh: function () { // 实例化刷新组件
            if (self._refreshIds.length == 0) {
                self._refreshIds = ['scroll1'];
            }
            this._super(win);
        },
        _refreshCb: function (goods) {// 刷新组件回调函授
            var _super = this._super;
            app.ajax({
                xurl: selectArg.url,
                xdata: {
                    page:goods.page+1,
                    limit: goods.limit,
                    keyword: searchData.keyword || selectArg.keyword
                },
                cb: function (result) {
                    if (result.ok) {
                        var data = result.data.data;
                        if (data.length > 0) {
                            data.forEach(function (d, index) {
                                var NAME='';
                                selectArg.keyArray.forEach(function (key, i) {
                                    if (i == 0)
                                        NAME = d[key];
                                    else
                                        NAME += ('('+d[key]+')');

                                });
                                d.NAME = NAME;
                            })
                        }
                        goods.data.pushArray(data, goods.page == 0);

                        _super({
                            obj: goods,
                            dataLen: data.length,
                            nodata: selectArg.nodata
                        });
                    }
                }
            });
        },
        _search: function (data) {
            searchData.keyword = data.keyword;
            self._refresh()
        },
        _ready: function () {

            Vue.component('selectitem', {
                template: app.getByid(doc, 'selectitem-template'),
                props: {
                    model: Array
                },
                methods: {
                    select: function (v) {
                        selectArg.cb(v);
                    }
                }
            });

        },
        _lazy: function () {
            this._super();
        }
    });

});